@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

set COMMAND_FILE=projects.txt
set LOG_FILE=git_clone_log_%date:~0,4%%date:~5,2%%date:~8,2%.txt

if not exist "%COMMAND_FILE%" (
    echo 错误: 找不到命令文件 %COMMAND_FILE%
    pause
    exit /b 1
)

echo 克隆开始时间: %date% %time% > "%LOG_FILE%"
echo 开始克隆项目...

set /a COUNTER=0
set /a SUCCESS_COUNT=0
set /a FAIL_COUNT=0

for /f "usebackq delims=" %%i in ("%COMMAND_FILE%") do (
    set /a COUNTER+=1
    echo. >> "%LOG_FILE%"
    echo 正在执行第!COUNTER!个项目: %%i >> "%LOG_FILE%"
    echo 正在克隆第!COUNTER!个项目...
    
    %%i
    
    if !errorlevel! equ 0 (
        echo 第!COUNTER!个项目克隆成功 >> "%LOG_FILE%"
        set /a SUCCESS_COUNT+=1
    ) else (
        echo 第!COUNTER!个项目克隆失败 >> "%LOG_FILE%"
        set /a FAIL_COUNT+=1
    )
)

echo. >> "%LOG_FILE%"
echo 克隆完成时间: %date% %time% >> "%LOG_FILE%"
echo 成功: %SUCCESS_COUNT% 个, 失败: %FAIL_COUNT% 个 >> "%LOG_FILE%"

echo.
echo 所有项目克隆完成！
echo 成功: %SUCCESS_COUNT% 个, 失败: %FAIL_COUNT% 个
echo 详细日志请查看: %LOG_FILE%
pause